package com.yanqu.road.server.cmd.activity.suitang;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.suitang.SuiTang;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.suitang.CrossSuiTangMgr;
import com.yanqu.road.server.manager.activity.suitang.activity.CrossSuiTangActivity;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = CrossProtocol.C2_SUI_TANG_AUTO_SETTING_INGOTS_OPERATE, desc = "自动设置元宝操作")
public class CrossSuiTangAutoSettingIngotsOperateCmd extends CrossUnionCommand {

    SuiTang.CrossSuiTangAutoSettingIngotsOperateReqMsg reqMsg;

    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = SuiTang.CrossSuiTangAutoSettingIngotsOperateReqMsg.parseFrom(packet.getBytes());
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossSuiTangActivity activity = CrossSuiTangMgr.getActivity(reqMsg.getActivityId(), groupId);
        if (activity == null) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        activity.setLastReqTime(userId);
        activity.autoSettingIngotsOperateByCmd(packet.getPlayerId(), reqMsg);
    }

    @Override
    public void sendData() {
        if (ret != 0) {
            SuiTang.CrossSuiTangAutoSettingIngotOperateFromCrossMsg.Builder respMsg = SuiTang.CrossSuiTangAutoSettingIngotOperateFromCrossMsg.newBuilder();
            respMsg.setRet(ret);
            respMsg.setOperateType(reqMsg.getReq().getOperateType());
            respMsg.setOffsetIngotsTimes(reqMsg.getReq().getOffsetIngotsTimes());
            MessageHelper.sendPacket(GameProtocol.S_SUI_TANG_AUTO_SETTING_INGOTS_OPERATE_FROM_CROSS, respMsg, userId);
        }

    }
}
